package com.example.cstr.controller;

import com.example.cstr.entity.EducationTrainClass;
import com.example.cstr.entity.Message;
import com.example.cstr.service.EducationTrainClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

//这个类的所有方法返回的数据直接写给浏览器。（如果是对象转为json数据）
@RestController
@RequestMapping("/api/EducationTrainClass")
@Api(tags = "教育培训类别")
public class EducationTrainClassController {
    @Resource
    private EducationTrainClassService educationTrainClassService;

    @ApiOperation(value = "添加教育培训类别")
    @PostMapping("/add")
    public Message insertEducationTrainClass(EducationTrainClass educationTrainClass){
        return educationTrainClassService.insertSelective(educationTrainClass)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "删除教育培训类别")
    @DeleteMapping("/delete")
    public Message deleteEducationTrainClass(Integer etcId){
        return educationTrainClassService.deleteByPrimaryKey(etcId)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "修改教育培训类别")
    @PutMapping("/update")
    public Message updateEducationTrainClass(EducationTrainClass educationTrainClass){
        return educationTrainClassService.updateByPrimaryKeySelective(educationTrainClass)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "根据教育培训类别id查询教育培训类别信息")
    @GetMapping("/select")
    public Message selectEducationTrainClass(Integer etcId){
        return educationTrainClassService.selectByPrimaryKey(etcId)!=null?Message.success(null).add(educationTrainClassService.selectByPrimaryKey(etcId)):Message.fail(null);
    }

    @ApiOperation(value = "查询所有教育培训类别信息")
    @GetMapping("/selectAll")
    public Message selectAllEducationTrainClass(){
        return Message.success(null).add(educationTrainClassService.selectAllEducationTrainClass());
    }

    @ApiOperation(value = "分页查询-查询所有教育培训类别信息")
    @GetMapping("/pagingSearch")
    public Message PagingSearch(@RequestParam Integer pageNum,@RequestParam Integer size){
        return educationTrainClassService.PagingSearch(pageNum,size);
    }

    @ApiOperation(value = "通过用户id查询教育培训类别id")
    @GetMapping("/selectEtcIdByWorkId")
    public Message selectEtcIdByWorkId(Integer workId){
        return educationTrainClassService.selectEtcIdByWorkId(workId)!=null?Message.success(null).add(educationTrainClassService.selectEtcIdByWorkId(workId)):Message.fail(null);
    }

    @ApiOperation(value = "根据年度id查询教育培训类别信息")
    @GetMapping("/selectAllByYearId")
    public Message selectAllByYearId(Integer yearId){
        return educationTrainClassService.selectAllByYearId(yearId)!=null?Message.success(null).add(educationTrainClassService.selectAllByYearId(yearId)):Message.fail(null);
    }

}
